package com.haizol.service.impl.common;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.haizol.repository.AxxcSelfRepository;
import com.haizol.service.common.AxxcSelfInnerService;
import com.haizol.service.common.BaseEntity;
import com.haizol.service.common.BaseVo;

public abstract class AxxcSelfAbstractServiceImpl<T extends BaseEntity, V extends BaseVo>
		implements AxxcSelfInnerService<T, V> {
	Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	AxxcSelfRepository<T, Integer> axxcSelfRepository;

	protected abstract V entityToVo(T t);

	@Override
	public List<V> listAll() {
		return this.axxcSelfRepository.findAll().stream().map(this::entityToVo).collect(Collectors.toList());
	}

	@Override
	public V selectByPrimaryKey(Integer id) {
		Optional<T> optional = this.axxcSelfRepository.findById(id);

		if (optional.isPresent()) {
			return this.entityToVo(optional.get());
		}
		return null;
	}

}
